const Router = require('koa-router');
const UserAccount = require('../controller/useraccount');
const router = Router({
    prefix: '/api'
})

router
.all('/useraccount', async (ctx, next) => {
    let method = ctx.request.method;
    let result;
    switch (method) {
        case 'GET': 
        // 获取列表数据
            result = await UserAccount.list(ctx);
        break;
        case 'POST': 
        // 新增数据
            result = await UserAccount.create(ctx);
        break;
        default: await next();
        break;
    }
})
.all('/useraccount/:id', async (ctx, next) => {
    let method = ctx.request.method;
    let result;
    switch (method) {
        // 获取单个数据
        case 'GET': result = await UserAccount.fetch(ctx);
        break;
        // 修改单个数据
        case 'PUT': result = await UserAccount.put(ctx);
        break;
        // 删除单个数据
        case 'DELETE': result = await UserAccount.delete(ctx);
        break;
        default: await next();
        break;
    }
})
.post('/login', async (ctx, next) => {
    await UserAccount.login(ctx);
})
.post('/useraccount/exchangetoken', async (ctx, next) => {
    await UserAccount.exchangetoken(ctx);
})


module.exports = router;